package edu.gdkm.dao;

import edu.gdkm.pojo.Project;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProjectDao {

    // 根据ID查询
    @Select("SELECT * FROM Projects WHERE project_id = #{projectId}")
    Project selectById(Integer projectId);

    // 根据简历ID查询
    @Select("SELECT * FROM Projects WHERE resume_id = #{resumeId} ORDER BY start_date DESC")
    List<Project> selectByResumeId(Integer resumeId);

    // 查询所有
    @Select("SELECT * FROM Projects")
    List<Project> selectAll();

    // 新增
    @Insert("INSERT INTO Projects(resume_id, name, description, role, start_date, end_date, is_current, url) " +
            "VALUES(#{resumeId}, #{name}, #{description}, #{role}, #{startDate}, #{endDate}, #{isCurrent}, #{url})")
    @Options(useGeneratedKeys = true, keyProperty = "projectId")
    int insert(Project project);

    // 更新
    @Update("UPDATE Projects SET resume_id = #{resumeId}, name = #{name}, description = #{description}, " +
            "role = #{role}, start_date = #{startDate}, end_date = #{endDate}, is_current = #{isCurrent}, " +
            "url = #{url} WHERE project_id = #{projectId}")
    int update(Project project);

    // 删除
    @Delete("DELETE FROM Projects WHERE project_id = #{projectId}")
    int delete(Integer projectId);
    
    // 根据简历ID删除
    @Delete("DELETE FROM Projects WHERE resume_id = #{resumeId}")
    int deleteByResumeId(Integer resumeId);
}
    